<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
  <meta charset="utf-8">
  <title>列表页面</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-form-pane" lay-filter="LAY-atomic-front-form">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">服务名称</label>
          <div class="layui-input-block">
            <input type="text" name="serviceName" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">服务编码</label>
          <div class="layui-input-block">
            <input type="text" name="serviceCode" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block">
            <select name="status" id="status" lay-search>
              <option value="">全部</option>
              <option th:each="map,idx:${statusList}" th:value="${map.key}" th:text="${map.value}"></option>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="LAY-atomic-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
          </button>
          <button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="LAY-atomic-front-reset">
            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 重置
          </button>
        </div>
      </div>
    </div>

    <div class="layui-card-body">
      <div class="layui-btn-group" style="padding-bottom: 10px;">
        <!--刷新table-->
        <button type="button" class="layui-btn layui-btn-normal btn-op-atomic layui-btn-sm" data-type="refresh">
          <i class="layui-icon">&#xe666;</i>刷新
        </button>
        <!-- 新增 -->
        <button sec:authorize="hasAuthority('mss:template:add')" type="button" class="layui-btn layui-btn-normal btn-op-atomic layui-btn-sm" data-type="add">
          <i class="layui-icon">&#xe654;</i>新增
        </button>
      </div>

      <!--table 定义-->
      <table id="LAY-atomic-table" lay-filter="LAY-atomic-table"></table>
      <!--table 列转换-->
      <script type="text/html" id="statusSwitchTpl">
        <input type="checkbox" disabled name="status" value="{{d.status}}" lay-skin="switch" lay-text="启用|禁用" {{ d.status== 'Y' ?'checked' : '' }}>
      </script>

      <!--列表操作项-->
      <script type="text/html" id="atomic-table">
        <a sec:authorize="hasAuthority('mss:template:edit')" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a sec:authorize="hasAuthority('mss:template:del')" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/'
  }).extend({
    //设定模块别名，模块名是使用layui.模块名  模块文件是 js名字。不设置模块名 = 模块文件名
    atomicInfo: 'modules/esb/atomicInfo'
  }).use(['atomicInfo'], function(){
    const $ = layui.$
        ,admin = layui.admin
        ,form = layui.form
        ,table = layui.table
        ,layer = layui.layer
        ,dropdown = layui.dropdown
        ,atomicInfo = layui.atomicInfo
        ,flying = layui.flying;

    //监听搜索
    form.on('submit(LAY-atomic-front-search)', function (data) {
      let field = data.field;
      //执行重载
      table.reload('LAY-atomic-table', {
        where: field
      });
    });
    // 监听重置
    form.on('submit(LAY-atomic-front-reset)', function (data) {
      let field = data.field;
      for (let key of Object.keys(field)) {
        field[key] = '';
      }
      form.val("LAY-atomic-front-form", field);
    });


    //事件
    let active = {
      add: function () {
        atomicInfo.handleEdit('新增', '');
      }
      , refresh: function () {
        let data = form.val("LAY-atomic-front-form");
        //执行重载 数据刷新
        table.reload('LAY-atomic-table', {
          where: data
        });
      }
    };

    //执行事件操作
    layui.$('.layui-btn.btn-op-atomic').on('click', function () {
      let type = layui.$(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    //监听工具条
    table.on('tool(LAY-atomic-table)', function (obj) {
      let line_data = obj.data;

      if (obj.event === 'edit') {
        // 编辑
        atomicInfo.handleEdit('修改', line_data.id);
      } else if (obj.event === 'del') {
        // 删除
        atomicInfo.handleDelete(line_data.id);
      }
    });
  });
</script>
</body>
</html>
